//
//  RouteCell.m
//  CarLifes
//
//  Created by yu on 2017/9/30.
//  Copyright © 2017年 jpas. All rights reserved.
//

#import "RouteCell.h"

@interface RouteCell ()
{
    UIColor *_borderColor;
    UIColor *_bgColor;
    UIColor *_strategyColor;
    UIColor *_strategyBgColor;
    UIColor *_timeColor;
    UIColor *_distanceColor;
}

@end

@implementation RouteCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    if (@available(iOS 13.0, *)) {
        UIColor *borderColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kRgb(169, 169, 169);
            } else {
                return kRgb(74, 74, 74);
            }
        }];
        _borderColor = borderColor;
        
        UIColor *bgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kRgb(242, 242, 242);
            } else {
                return kRgb(40, 40, 40);
            }
        }];
        _bgColor = bgColor;
        
        UIColor *strategyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kTextBlackColor;
            } else {
                return kDarkTextColor;
            }
        }];
        _strategyColor = strategyColor;
        
        UIColor *strategyBgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kRgb(169, 169, 169);
            } else {
                return kRgb(74, 74, 74);
            }
        }];
        _strategyBgColor = strategyBgColor;
        
        UIColor *timeColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kTextBlackColor;
            } else {
                return kDarkTextColor;
            }
        }];
        _timeColor = timeColor;
        
            
        } else {
            _borderColor = kButtonGrayColor;
            _bgColor = kBackGroundLightGrayColor;
            _strategyBgColor = kButtonGrayColor;
            _strategyColor = kTextBlackColor;
            _timeColor = kTextBlackColor;
            _distanceColor = kTextBlackColor;
        }
        
        [self resetCellBorderColor:_borderColor bgColor:_bgColor strategyLabelBgColor:_strategyBgColor strategyLabelTextColor:_strategyColor timeLabelTextColor:_timeColor distanceLabelTextColor:_timeColor];
}

- (void)resetCellBorderColor:(UIColor *)borderColor
                     bgColor:(UIColor *)bgColor
        strategyLabelBgColor:(UIColor *)strategyLabelBgColor
      strategyLabelTextColor:(UIColor *)strategyLabelTextColor
          timeLabelTextColor:(UIColor *)timeLabelTextColor
      distanceLabelTextColor:(UIColor *)distanceLabelTextColor
{
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = 4;
    self.layer.borderWidth = 0.5;
    self.layer.borderColor = borderColor.CGColor;

    self.backgroundColor = bgColor;
    
    self.strategyLabel.backgroundColor = strategyLabelBgColor;
    self.strategyLabel.textColor = strategyLabelTextColor;
    self.timeLabel.textColor = timeLabelTextColor;
    self.distanceLabel.textColor = distanceLabelTextColor;
}

- (void)setSelected:(BOOL)selected
{
    [super setSelected:selected];

    if (selected)
    {
        if (@available(iOS 13.0, *)) {
            UIColor *borderColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                    return kBaseColor;
                } else {
                    return kBaseColorDark;
                }
            }];
            _borderColor = borderColor;
            
            UIColor *bgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                    return UIColor.whiteColor;
                } else {
                    return kRgb(40, 40, 40);
                }
            }];
            _bgColor = bgColor;
            
            UIColor *strategyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                    return UIColor.whiteColor;
                } else {
                    return kDarkTextColor;
                }
            }];
            _strategyColor = strategyColor;
            
            UIColor *strategyBgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                    return kBaseColor;
                } else {
                    return kBaseColorDark;
                }
            }];
            _strategyBgColor = strategyBgColor;
            
            UIColor *timeColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
                if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                    return kBaseColor;
                } else {
                    return kRgb(20, 120, 240);
                }
            }];
            _timeColor = timeColor;
        } else {
            _borderColor = kBaseColor;
            _bgColor = UIColor.whiteColor;
            _strategyBgColor = kBaseColor;
            _strategyColor = UIColor.whiteColor;
            _timeColor = kTextBlackColor;
            _distanceColor = kTextBlackColor;
        }
        
        [self resetCellBorderColor:_borderColor bgColor:_bgColor strategyLabelBgColor:_strategyBgColor strategyLabelTextColor:_strategyColor timeLabelTextColor:_timeColor distanceLabelTextColor:_timeColor];
    }
    else
    {
        PPLog(@"unselectedooooo");
        if (@available(iOS 13.0, *)) {
        UIColor *borderColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kRgb(169, 169, 169);
            } else {
                return kRgb(74, 74, 74);
            }
        }];
        _borderColor = borderColor;
        
        UIColor *bgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kRgb(242, 242, 242);
            } else {
                return kRgb(40, 40, 40);
            }
        }];
        _bgColor = bgColor;
        
        UIColor *strategyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kTextBlackColor;
            } else {
                return kDarkTextColor;
            }
        }];
        _strategyColor = strategyColor;
        
        UIColor *strategyBgColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kRgb(169, 169, 169);
            } else {
                return kRgb(74, 74, 74);
            }
        }];
        _strategyBgColor = strategyBgColor;
        
        UIColor *timeColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traitCollection) {
            if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleLight) {
                return kTextBlackColor;
            } else {
                return kDarkTextColor;
            }
        }];
        _timeColor = timeColor;
        
        } else {
        _borderColor = kButtonGrayColor;
        _bgColor = kBackGroundLightGrayColor;
        _strategyBgColor = kButtonGrayColor;
        _strategyColor = kTextBlackColor;
        _timeColor = kTextBlackColor;
        _distanceColor = kTextBlackColor;
        }
        
        [self resetCellBorderColor:_borderColor bgColor:_bgColor strategyLabelBgColor:_strategyBgColor strategyLabelTextColor:_strategyColor timeLabelTextColor:_timeColor distanceLabelTextColor:_timeColor];
    }
}

@end
